// sectordump.c
// a utility to write bootloaders to floppy images
// by Anshu Chimala

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char **argv) {
	printf("sectordump 0.1 -- by Anshu Chimala\r\n");
	if(argc != 3) {
		printf("USAGE: sectordump <floppy.img> <bootloader.bin>\r\n\r\n");
		return 1;
	}
	printf("\tdumping 512 bytes of %s to %s\r\n", argv[1], argv[2]);
	
	char boot_buf[512];
	int floppy_desc, file_desc;
	floppy_desc = open(argv[1], O_RDONLY);
	read(floppy_desc, boot_buf, 512); //assume it ends with 0x55AA
	file_desc = open(argv[2], O_RDWR);
	write(file_desc, boot_buf, 512);
	close(file_desc);
}
